﻿@namespace BlazorComponent
@inherits BDomComponentBase
@typeparam TItem
@typeparam TItemValue
@typeparam TValue

<BList @attributes="@GetAttributes(typeof(BList))">
    @{
        var children = new List<RenderFragment?>();

        for (var index = 0; index < Items.Count; index++)
        {
            var item = Items[index];

            if (HideSelected && HasItem(item))
            {
                continue;
            }
            
            if (ItemHeader?.Invoke(item) != null)
            {
                children.Add(RenderPart(typeof(BSelectListHeader<,,>), ItemHeader(item), arg0Name: "Header"));
            }
            else if (ItemDivider?.Invoke(item) is true)
            {
                children.Add(RenderPart(typeof(BSelectListDivider<,,>)));
            }
            else
            {
                children.Add(RenderPart(typeof(BSelectListTile<,,>), item, index));
            }
        }

        if (children.Count == 0)
        {
            children.Add(NoDataContent ?? RenderPart(typeof(BSelectListStaticNoDataTile<,,>)));
        }

        if (PrependItemContent != null)
        {
            children.Insert(0, PrependItemContent);
        }

        if (AppendItemContent != null)
        {
            children.Add(AppendItemContent);
        }

        foreach (var child in children)
        {
            @child
        }
    }
</BList>
